<?php

use Illuminate\Support\Facades\Cache;
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::pattern('id', '[0-9]+');
Route::group(array('prefix' => '/'), function(){
	Route::get("/","HomeController@showHome");
	Route::get("product-list/{id?}","HomeController@showProducts");
	Route::get("product/{id}","HomeController@showProduct");
	Route::get("cart","HomeController@showCart");
	Route::post("product/favorite",array('before'=>'auth','uses'=>"HomeController@postFavorite"));
	
	Route::post("login", array('before'=> 'csrf','uses'=>"HomeController@postLogin"));
	Route::post("forgot",array('before'=> 'csrf','uses'=>"HomeController@postForgot"));
	Route::get("password/reset/{token}",array('uses'=>"HomeController@showResetPassword"));
	Route::post("password/reset",array('before'=> 'csrf','uses'=>"HomeController@postResetPassword"));
	Route::post("verify-code",array('before'=> 'csrf','uses'=>"HomeController@sendVerifyCode"));
	
	Route::post("register",array('before'=> 'csrf','uses'=>"HomeController@postRegister"));
	Route::get("register/active/{token}",array('uses'=>"HomeController@doActiveRegister"));
	Route::get('logout', array('uses'=>'HomeController@logout'));
	
	/**订单提交页面*/
	Route::get("order-form",array('before'=> 'auth|csrf','uses'=>"HomeController@showOrderForm"));
	Route::post("user/address/add",array('before'=> 'auth|csrf','uses'=>"UserController@postUserAddress"));
	
	Route::get("user/address/provinces",array('before'=> 'auth','uses'=>"UserController@getProvinces"));
	Route::get("user/address/cities/{id}",array('before'=> 'auth','uses'=>"UserController@getCities"));
	Route::get("user/address/districts/{id}",array('before'=> 'auth','uses'=>"UserController@getDistricts"));
	
	
	Route::post("order/check-quantity",array('before'=> 'auth','uses'=>"UserController@checkOrderQuantity"));
	Route::post("order",array('before'=> 'auth|csrf','uses'=>"UserController@postOrder"));
	Route::get("order/pay/{id}",array('before'=> 'auth','uses'=>"PayController@showOrderPay"));
	Route::post("order/pay/",array('before'=> 'auth|csrf','uses'=>"PayController@postOrderPay"));
	Route::get("order/pay/return",array('before'=> 'auth','uses'=>"PayController@showOrderPayReturn"));
	Route::post("order/pay/notify",array('uses'=>"PayController@postOrderPayNotify"));
	
	Route::post("order/pay/union/front",array('before'=> 'auth','uses'=>"PayController@postUnionpayFront"));
	Route::post("order/pay/union/back",array('uses'=>"PayController@postUnionpayBack"));
	
	/**我的用户*/
	Route::get("user",array('before'=> 'auth','uses'=>"UserController@showUser"));
	Route::post("user/unbind",array('before'=> 'auth','uses'=>"UserController@unbind"));
	Route::get("user/order-list",array('before'=> 'auth','uses'=>"UserController@showUserOrders"));
	Route::get("user/order/{id}",array('before'=> 'auth','uses'=>"UserController@showUserOrderDetail"));
	Route::get("user/address-list",array('before'=> 'auth','uses'=>"UserController@showUserAddresses"));
	Route::post("user/address/delete",array('before'=> 'auth','uses'=>"UserController@deleteUserAddress"));
	
	Route::get("user/info",array('before'=> 'auth','uses'=>"UserController@showUserInfo"));
	Route::post("user/update",array('before'=> 'auth|csrf','uses'=>"UserController@updateUserInfo"));
	
	Route::get("user/favorite-list",array('before'=> 'auth','uses'=>"UserController@showUserFavorites"));
	Route::post("user/favorite/delete",array('before'=> 'auth','uses'=>"UserController@deleteUserFavorite"));
	
	/**
	 * 用户搜索
	 */
	Route::post('search',array('before'=> 'csrf','uses'=>"HomeController@postSearch"));
	Route::get('search/{q}',array('uses'=>"HomeController@showSearch"));
	
	/**
	 * 专栏
	 */
	Route::get('stories',array('uses'=>"HomeController@showStories"));
	
	
	Route::get('image', array('as' => 'image',function(){
		$data = Input::all();
		return Images::response($data);
	}));
	
	Route::get('about',array('uses'=>"HomeController@showAbout"));
	Route::get('contact',array('uses'=>"HomeController@showContact"));
	Route::get('faq',array('uses'=>"HomeController@showFaq"));
	Route::get('guide',array('uses'=>"HomeController@showGuide"));
	Route::get('privacy',array('uses'=>"HomeController@showPrivacy"));
	Route::get('terms',array('uses'=>"HomeController@showTerms"));
	
	//微信支付接口,授权
	Route::get('wx/authed',array('uses'=>"WeixinController@receiveAuthed"));
	Route::post('wx/pay/notify',array('uses'=>"WeixinController@payNofity"));

	Route::get('/test', function(){
		//输出图片
		// 	$img = Image::canvas(800, 600, '#ff0000');
		// 	return $img->response();
		//upload iamge
		//Image::make(Input::file('photo'))->resize(300, 200)->save('foo.jpg');
		// $img = Image::canvas(800, 600, '#ff0000');
		// create response and add encoded image data
		//$response = Response::make($img->encode('png'));
		// set content-type
		//$response->header('Content-Type', 'image/png');
		// output
		//return $response;
		
		/*
		$data = array('token'=>'熊旭');
		Mail::send('emails.auth.reminder', $data, function($message){
			$message->to('609015534@qq.com', '熊旭')->subject('Welcome!');
		});
		return Images::test();*/
		
		Queue::push(function($job){
			//Account::delete($id);
			if ($job->attempts() > 5){
				$job->delete();
				return;
			}
			Log::info("test queue,jobId:".$job->getJobId().",attmepts:".$job->attempts());
			$job->release(10);
		});
	});
});





Route::group(array('before' => 'admin','prefix' => 'admin'), function()
{
	Route::get('/', array('as'=>'admin','uses' => "AdminController@showAdmin"));
	
	Route::get('user', array('as'=>'user','uses' => "AdminController@showUsers"));
	Route::get('user/{id}', array('as'=>'user.detail','uses'=>'AdminController@showUserDetail'));
	Route::post('user/toggle', array('as'=>'user.toggle','uses' => "AdminController@toggleUser"));
	
	Route::get('login',  array('as' => 'showlogin', 'uses' => 'AdminController@showLogin'));
	Route::post('login', array('before'=> 'csrf','as' => 'login', 'uses' => 'AdminController@login'));
	Route::get('logout', array('as'=>'logout','uses'=>'AdminController@logout'));
	Route::post('banner/add', array('as'=>'banner-add','uses'=>'AdminController@postBanner'));
	Route::post('banner/delete', array('as'=>'banner-del','uses'=>'AdminController@deleteBanner'));
	
	Route::post('home-style', array('as'=>'home-style','uses'=>'AdminController@postHomeStyle'));
	
	//产品类别
	Route::get('product/category', array('as'=>'product.category','uses'=>'ProductController@showCategorys'));
	Route::get('product/category/add', array('as'=>'product.category.add.show','uses'=>'ProductController@showCategoryAdd'));
	Route::post('product/category/add', array('as'=>'product.category.add','uses'=>'ProductController@postCategory'));
	Route::get('product/category/update/{id}', array('as'=>'product.category.update.show','uses'=>'ProductController@showCategoryUpdate'));
	Route::post('product/category/update', array('as'=>'product.category.update','uses'=>'ProductController@updateCategory'));
	Route::post('product/category/delete', array('as'=>'product.category.delete','uses'=>'ProductController@deleteCategory'));
    Route::post('product/category/toggle', array('as'=>'category.toggle','uses'=>'ProductController@toggleCategory'));

    //通知
	Route::get('notice', array('as'=>'notice','uses'=>'AdminController@showNotices'));
	Route::get('notice/add', array('as'=>'notice.add.show','uses'=>'AdminController@showNoticeAdd'));
	Route::post('notice/add', array('as'=>'notice.add','uses'=>'AdminController@postNotice'));
	Route::get('notice/update/{id}', array('as'=>'notice.update.show','uses'=>'AdminController@showNoticeUpdate'));
	Route::post('notice/update', array('as'=>'notice.update','uses'=>'AdminController@updateNotice'));
	Route::post('notice/delete', array('as'=>'notice.delete','uses'=>'AdminController@deleteNotice'));
	
	//产品
	Route::get('product', array('as'=>'product','uses'=>'ProductController@showProducts'));
	Route::get('product/add', array('as'=>'product.add.show','uses'=>'ProductController@showProductAdd'));
	Route::post('product/add', array('as'=>'product.add','uses'=>'ProductController@postProduct'));
	Route::post('product/toggle', array('as'=>'product.toggle','uses'=>'ProductController@toggleProduct'));
	Route::post('product/delete', array('as'=>'product.delete','uses'=>'ProductController@deleteProduct'));
	Route::post('product/swap', array('as'=>'product.swap','uses'=>'ProductController@postProductSwapSort'));
	Route::post('product/ext/add', array('as'=>'product.ext.add','uses'=>'ProductController@postProductExt'));
	Route::get('product/update/{id}', array('as'=>'product.update.show','uses'=>'ProductController@showProductUpdate'));
	Route::post('product/image/add', array('as'=>'product.image.add','uses'=>'ProductController@postProductImage'));
	Route::post('product/image/delete', array('as'=>'product.image.delete','uses'=>'ProductController@deleteProductImage'));
	Route::post('product/image/swap', array('as'=>'product.image.swap','uses'=>'ProductController@postProductImageSwapSort'));
	Route::post('product/size/add', array('as'=>'product.size.add','uses'=>'ProductController@postProductSize'));
	Route::post('product/size/update', array('as'=>'product.size.update','uses'=>'ProductController@updateProductSize'));
	Route::post('product/color/add', array('as'=>'product.color.add','uses'=>'ProductController@postProductColor'));
	Route::post('product/color/update', array('as'=>'product.color.update','uses'=>'ProductController@updateProductColor'));
	Route::post('product/get', array('as'=>'product.get','uses'=>'ProductController@getProduct'));
	Route::post('product/quantity/update', array('as'=>'product.quantity.update','uses'=>'ProductController@updateProductQuantity'));
	
	
	//地址信息
	Route::get('address/province', array('as'=>'address.province','uses'=>'AdminAddressController@showProvinces'));
	Route::get('address/city/{id}', array('as'=>'address.city','uses'=>'AdminAddressController@showCitys'));
	Route::get('address/district/{id}', array('as'=>'address.district','uses'=>'AdminAddressController@showDistricts'));

	//订单
	Route::get('order', array('as'=>'order','uses'=>'AdminOrderController@showOrders'));
	Route::get('order/{id}', array('as'=>'order.detail','uses'=>'AdminOrderController@showOrder'));
	Route::post('order/delivery', array('as'=>'order.delivery','uses'=>'AdminOrderController@postDelivery'));
	Route::post('order/returns', array('as'=>'order.returns','uses'=>'AdminOrderController@postReturns'));
	Route::post('order/remark', array('as'=>'order.remark','uses'=>'AdminOrderController@postRemark'));
	Route::post('order/offline-pay', array('as'=>'order.offline-pay','uses'=>'AdminOrderController@postOfflinePay'));
	
	
	//专栏
	Route::get('story', array('as'=>'story','uses'=>'AdminStoryController@showStories'));
	Route::get('story/add', array('as'=>'story.add.show','uses'=>'AdminStoryController@showStoryAdd'));
	Route::post('story/add', array('as'=>'story.add','uses'=>'AdminStoryController@postStory'));
	Route::post('story/delete', array('as'=>'story.delete','uses'=>'AdminStoryController@deleteStory'));
	
	//Project
	Route::get('project', array('as'=>'project','uses'=>'AdminProjectController@showProjects'));
	Route::get('project/add', array('as'=>'project.add.show','uses'=>'AdminProjectController@showProjectAdd'));
	Route::post('project/add', array('as'=>'project.add','uses'=>'AdminProjectController@postProject'));
	Route::post('project/delete', array('as'=>'project.delete','uses'=>'AdminProjectController@deleteProject'));
	
	Route::match(array('GET', 'POST'),"ueditor", array('as'=>'ueditor','uses'=>'UEditorController@service'));
});

